// select 默认某项不能删除
const vSelectTagDel = {
  name: 'select-tag-del',
  mounted: (el, binding) => {
    const [defaultValues, selectValue] = binding.value
    // 需要隐藏的标签索引
    const indexs = []
    selectValue.map((item, index) => {
      defaultValues.map((defaultItem) => {
        if (item === defaultItem.userId) {
          indexs.push(index)
        }
      })
    })
    const dealStyle = function (tags) {
      tags.forEach((el, index) => {
        if (indexs.includes(index) && ![...el.classList].includes('select-tag-close-none')) {
          el.style.display = 'none'
        }
      })
    }
    // 设置样式隐藏 close icon
    let tags = el.querySelectorAll('.el-tag__close')

    if (tags.length === 0) {
      // 初始化tag为空处理
      setTimeout(() => {
        let tagTemp = el.querySelectorAll('.el-tag__close')
        dealStyle(tagTemp)
      })
    } else {
      setTimeout(() => {
        dealStyle(tags)
      })
    }
  },
}

export default vSelectTagDel
